♻️ Send account creation email asynchronously via BackgroundTasks#1505
♻️ Send account creation email asynchronously via BackgroundTasks#1505saleemasekrea000 wants to merge 3 commits intofastapi:masterfrom
Conversation
|
@alejsdev |
YuriiMotov
left a comment
There was a problem hiding this comment.
@saleemasekrea000, hello!
Thanks for the interest in project!
The problem here is that BackgroundTasks can fail silently and in this case user will not receive the email, and admin will not notice it.
With Celery (or other similar tools) we would have retry mechanism to ensure that email has been sent.
Having this I'm not sure it's good idea to move this to BG tasks
|
Hi @YuriiMotov ,
is this approach acceptable? |
|
Thanks all! I think it's better to make sure the email is properly sent or scheduled before returning the response, so that if it fails, an error would be returned. So I'll pass on this, but thanks for the interest. ☕ |
Making it a background task improves responsiveness and user experience.
For future
If you need to perform heavy background computation and you don't necessarily need it to be run by the same process (for example, you don't need to share memory, variables, etc), you might benefit from using other bigger tools like Celery
According to the FastAPI docs :
https://fastapi.tiangolo.com/tutorial/background-tasks/?h=#technical-details